<template>
	<view>
		<view class="list">
			<u-cell class="spotList" customStyle="border-bottom:1rpx solid #EFEFEF" @click="toHref(item)"
				v-for="(item, index) in indexList" :key="index">
				<u-avatar slot="icon" shape="square" size="200" :src="item.coverImage"
					customStyle="border-radius:10px"></u-avatar>
				<view class="right" slot="title">
					<view class="p1">{{item.scenicSpotName}}</view>
					<view class="p2"><text>距离{{item.distence}}</text><text>|</text></text><text>{{item.scenicName}}</text>
					</view>
					<view class="p3"><text>{{item.scenicSpotName}}</text></view>
					<view class="p4" style="display: flex; justify-content: space-between;">
						<view class="" style=" display: flex; align-items: center;">
							<view class="money">￥</view>
							<view class="price">
								{{item.startPrice}}
							</view>
							起
						</view>
						<view
							style="font-size: 22rpx ; color: #EFEFEF; width: 128rpx; height: 56rpx; line-height: 56rpx; display: flex;align-items: center; text-align: center; border-radius: 50rpx;background: linear-gradient(to right, #FF7D43, #FFA414);">
							<text style="margin: 0 20rpx;">立即购买</text>
						</view>
					</view>
				</view>
			</u-cell>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				indexList: [],
				fromData: {
					limit: 4,
					page: 1,
					sort: 0,
				},
				lat:'',
				lon:''
			}
		},
		mounted() {
			let that = this;
			uni.getLocation({
				type: 'wgs84',
				success: function (res) {
					that.lat = res.latitude;
					that.lon = res.longitude;
					that.getRoomsList()
				}
			});
		},
		methods: {
			getRoomsList() {
				// console.log('999');
				this.$api.get('/api/scenic/page', this.fromData)
					.then(res => {
						// console.log(res, '-00000');
						this.indexList = res.data.data.list
						this.indexList.forEach(d=>{
							d.distence = this.getDistence(d.lat,d.lon)
						})
					})
			},

			//跳转详情
			toHref(item) {
				// console.log(item);
				uni.removeStorageSync('spid_old');
				uni.removeStorageSync('price_old');
				uni.navigateTo({
					url: "/pagesTrip/scenicSpots/spotDetail?spid=" + item.ismapId
				})
			},
			getDistence(lat,lon){
				var radLat1 = lat*Math.PI / 180.0;
				var radLat2 = this.lat*Math.PI / 180.0;
				var a = radLat1 - radLat2;
				var b = lon*Math.PI / 180.0 - this.lon*Math.PI / 180.0;
				var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a/2),2) +
				  Math.cos(radLat1)*Math.cos(radLat2)*Math.pow(Math.sin(b/2),2)));
				s = s *6378.137 ;// EARTH_RADIUS;
				s = Math.round(s * 10000) / 10000;
				s = s * 1000
				if (isNaN(s)) {
				  return 0+'m';
				}
				if (s > 1000) {
				  //    大于1000米时
				  s = Math.floor(s/1000 * 100) / 100;
				  s = s + 'km'
				} else {
				  //    小于1000米直接返回
				  s = s + 'm'
				}
				return s
			}
		}
	}
</script>
<style lang="less">
	.list {
		width: 96vw;
		box-sizing: border-box;
	}

	.right {
		margin-left: 26rpx;

		.p1 {
			color: #111111;
			font-size: 32rpx;
			font-family: PingFang-SC-Bold, PingFang-SC;
			font-weight: bold;

		}

		.p2 {
			font-size: 24rpx;
			color: #777;
			margin: 20rpx 0 22rpx;

			text:nth-child(2) {
				display: inline-block;
				margin: 0 15rpx;
				font-size: 20rpx;
				color: #EFEFEF;
			}
		}

		.p3 {
			text {
				display: inline-block;
				padding: 6rpx;
				background-color: #fff6e6;
				font-size: 22rpx;
				color: #FF7D01;
				margin-bottom: 18rpx;
				border-radius: 4rpx;
			}
		}

		.p4 {
			display: flex;
			font-size: 18rpx;
			color: #777;
			align-items: center;

			.money {
				font-size: 18rpx;
				color: #FF4141;
				margin-right: 4rpx;
			}

			.price {
				font-size: 30rpx;
				font-weight: bold;
				color: #FF4141;
				margin-right: 4rpx;
				font-family: Arial Bold, PingFang-SC-Bold, PingFang-SC;
				;
			}
		}
	}
</style>